package cqut.wys.controller;

import cqut.wys.domain.City;
import cqut.wys.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by wuyoushan on 2017/9/25.
 */
@RestController
public class CityRestController {

    @Autowired
    CityService cityService;

    /**
     * 插入 ES 新城市
     *
     * @param city City对象
     * @return Long
     */
    @PostMapping(value = "/api/city")
    public Long createCity(City city){
        return cityService.saveCity(city);
    }

    /**
     * AND 语句查询
     *
     * @param description 描述
     * @param score 评分
     * @return List<City>
     */
    @GetMapping(value = "/api/city/and/find")
    public List<City> findByDescriptionAndScore(@RequestParam(value = "description") String description,
                                                @RequestParam(value = "score") Integer score) {
        return cityService.findByDescriptionAndScore(description, score);
    }

    /**
     * OR 语句查询
     *
     * @param description 描述
     * @param score 评分
     * @return List<City>
     */
    @GetMapping(value = "/api/city/or/find")
    public List<City> findByDescriptionOrScore(@RequestParam(value = "description") String description,
                                               @RequestParam(value = "score") Integer score) {
        return cityService.findByDescriptionOrScore(description, score);
    }

    /**
     * 查询城市描述
     *
     * @param description 描述
     * @return List<City>
     */
    @GetMapping(value = "/api/city/description/find")
    public List<City> findByDescription(@RequestParam(value = "description") String description) {
        return cityService.findByDescription(description);
    }

    /**
     * NOT 语句查询
     *
     * @param description 描述
     * @return List<City>
     */
    @GetMapping(value = "/api/city/description/not/find")
    public List<City> findByDescriptionNot(@RequestParam(value = "description") String description) {
        return cityService.findByDescriptionNot(description);
    }

    /**
     * LIKE 语句查询
     *
     * @param description 描述
     * @return List<City>
     */
    @GetMapping()
    public List<City> findByDescriptionLike(@RequestParam(value = "description") String description) {
        return cityService.findByDescriptionLike(description);
    }
}
